local extension = Package("rfenghou_wei")
extension.extensionName = "aaa_fenghou"

local U = require "packages/utility/utility"
local RUtil = require "packages/aaa_fenghou/utility/rfenghou_util"

Fk:loadTranslationTable{
  ["rfenghou_wei"] = "颂魏",
}

local function AddWinAudio(general)
  local Win = fk.CreateActiveSkill{ name = general.name.."_win_audio" }
  Win.package = extension
  Fk:addSkill(Win)
end

--FY016 卞夫人 by cyc
--[[
-- 修改调用国战标记
local bianfuren = General:new(extension, "rfenghou__bianfuren", "wei", 3, 3, General.Female)
local wanxian = fk.CreateTriggerSkill{
  name = "rfenghou__wanxian",
  mute = true,
  switch_skill_name = "rfenghou__wanxian",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target.phase == Player.Discard and not target.dead and not player:isNude() then
      if player:getSwitchSkillState(self.name, false) == fk.SwitchYang then
        return true
      else
        return target:isWounded()
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local name = "ex_nihilo"
    if player:getSwitchSkillState(self.name, false) == fk.SwitchYin then
      name = "peach"
    end
    local pattern = "false"
    local cards = table.filter(player:getCardIds("he"), function (id)
      local card = Fk:cloneCard(name)
      card:addSubcard(id)
      card.skillName = self.name
      return not player:isProhibited(target, card)
    end)
    if #cards > 0 then
      pattern = tostring(Exppattern{ id = cards })
    end
    local card = room:askForCard(player, 1, 1, true, self.name, true, pattern, "#rfenghou__wanxian-invoke::"..target.id..":"..name)
    if #card > 0 then
      local use = {
        from = player.id,
        tos = {{target.id}},
        card = Fk:cloneCard(name),
      }
      use.card:addSubcard(card[1])
      use.card.skillName = self.name
      self.cost_data = use
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local dat = self.cost_data
    room:notifySkillInvoked(player, self.name, "support")
    if dat.card.name == "ex_nihilo" then
      player:broadcastSkillInvoke(self.name, 4)
    else
      player:broadcastSkillInvoke(self.name, 3)
    end
    room:useCard(dat)
    if player.dead then return end
    local status = player:getMark("rfenghou__wanxian") == 0 and "ping" or "ze"
    if status == "ping" then
      if target.dead or target:getHandcardNum() > target:getMaxCards() or target:isNude() then return end
      local use = U.askForPlayCard(room, target, nil, nil, self.name,
        "#rfenghou__wanxian-use", {bypass_times = true, extraUse = true})
      player:broadcastSkillInvoke(self.name, 1)
      if not use then
        local targets = room:getOtherPlayers(target)
        if #targets == 0 then return end
        local to, card = room:askForChooseCardAndPlayers(target, table.map(targets, Util.IdMapper), 1, 1, nil,
          "#rfenghou__wanxian-present", self.name, false, false)
        U.presentCard(target, room:getPlayerById(to[1]), card)
      end
    else
      if target.dead or target:getHandcardNum() <= target:getMaxCards() then return end
      player:broadcastSkillInvoke(self.name, 2)
      target._phase_end = true
      room:damage{
        to = target,
        damage = 1,
        skillName = self.name,
        damageType = fk.IceDamage,
      }
    end
  end,

  refresh_events = {fk.AfterSkillEffect},
  can_refresh = function (self, event, target, player, data)
    return target == player and table.contains({
      "vanguard_skill&", "yinyangfish_skill&", "companion_skill&", "companion_peach&", "wild_draw&", "wild_peach&"
    }, data.name)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name, 5)
    room:notifySkillInvoked(player, self.name, "switch")
    if player:getMark("rfenghou__wanxian") == 0 then
      room:setPlayerMark(player, "rfenghou__wanxian", 1)
    else
      room:setPlayerMark(player, "rfenghou__wanxian", 0)
    end
  end,
}
local zezheng = fk.CreateTriggerSkill{
  name = "rfenghou__zezheng",
  anim_type = "special",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and not player:isKongcheng() then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerHand then
          return true
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local cards = table.filter(player:getCardIds("h"), function(id)
      return not player:prohibitDiscard(id) and
        (table.every(player:getCardIds("h"), function(id2)
          return Fk:getCardById(id).number <= Fk:getCardById(id2).number
        end) or table.every(player:getCardIds("h"), function(id2)
          return Fk:getCardById(id).number >= Fk:getCardById(id2).number
        end))
    end)
    if #cards > 0 and player.room:askForSkillInvoke(player, self.name, nil, "#rfenghou__zezheng-invoke") then
      self.cost_data = {cards = cards}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data.cards, self.name, player, player)
    if not player.dead then
      --H.addHegMark(room, player, "companion")
    end
  end,
}
bianfuren:addSkill(wanxian)
bianfuren:addSkill(zezheng)
Fk:loadTranslationTable{
  ["rfenghou__bianfuren"] = "卞夫人",
  ["#rfenghou__bianfuren"] = "蹈和履贞",
  ["designer:rfenghou__bianfuren"] = "cyc",
  ["illustrator:rfenghou__bianfuren"] = "Mortal",

  ["rfenghou__wanxian"] = "挽弦",
  [":rfenghou__wanxian"] = "转换技，韵律技，一名角色的弃牌阶段开始时，你可以将一张牌当：①【无中生有】；②【桃】对其使用，然后："..
  "平：若其无需弃牌，其需使用或赠予一张牌；仄：若其仍需弃牌，改为受到1点冰冻伤害。<br>转韵：你失去国战标记后。<br>"..
  "<font color='grey'>\"<b>韵律技</b>\"<br>一种特殊的技能，分为“平”和“仄”两种状态。游戏开始时，韵律技处于“平”状态；满足“转韵”条件后，"..
  "韵律技会转换到另一个状态，且重置技能发动次数。",
  ["rfenghou__zezheng"] = "择正",
  [":rfenghou__zezheng"] = "每回合限一次，当你获得牌后，你可以弃置所有点数最大或最小的手牌，获得一枚“珠联璧合”。<br/>"..
  "<font color='grey'><small>"..
  "<b>珠联璧合</b>：出牌阶段，你可以弃一枚“珠联璧合”，摸两张牌；你可以弃一枚“珠联璧合”，视为使用【桃】。</small></font>",
  ["#rfenghou__wanxian-invoke"] = "挽弦：你可以将一张牌当【%arg】对 %dest 使用",
  ["#rfenghou__wanxian-use"] = "挽弦：请使用一张牌，否则需赠予一名角色一张牌",
  ["#rfenghou__wanxian-present"] = "挽弦：请赠予一名角色一张牌",
  ["#rfenghou__zezheng-invoke"] = "择正：是否弃置所有点数最大或最小的手牌，获得一枚“珠联璧合”？",
  ["$rfenghou__wanxian1"]="明日若再，何面目复相见也？",
  ["$rfenghou__wanxian2"]="曹君吉凶未可知，诸君岂可还家。",
  ["$rfenghou__wanxian3"]="为避叵测之祸而弃忠信之名，诸君何其愚哉！",
  ["$rfenghou__wanxian4"]="驰骋沙场妾不如君，安家定业君不如妾。",
  ["$rfenghou__wanxian5"]="薄暮浸雪，此间可补衾者，吾手之针线也。",
  ["$rfenghou__zezheng1"]="飞雪若柳絮，润春种之粟，拨秋收之望。",
  ["$rfenghou__zezheng2"]="瑞雪兆丰年，他日冰消雪融，必现万里好江山。",
  ["~rfenghou__bianfuren"] = "悼痛酷楚，情自不胜。",
}
--]]

local wangling = General:new(extension, "rfenghou__wangling", "wei", 4)
local mouding = fk.CreateViewAsSkill{
  name = "rfenghou__mouding",
  pattern = ".|.|.|.|.|trick",
  prompt = function ()
    return "#rfenghou__mouding:::"..Self:getMark("rfenghou__mouding_record")
  end,
  card_num = 1,
  card_filter = function (self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeTrick
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard(Self:getMark("rfenghou__mouding_record"))
    card:addSubcard(cards[1])
    card.skillName = self.name
    return card
  end,
  enabled_at_play = function(self, player)
    return player:getMark("rfenghou__mouding_record") ~= 0
  end,
  enabled_at_response = function(self, player, response)
    return not response and player:getMark("rfenghou__mouding_record") == "nullification"
  end,
}
local function MoudingClear(player, card_only)
  local room = player.room
  card_only = card_only or false
  local n = math.abs(player:getMark("rfenghou__xingbian_trickcount") - player:getMark("rfenghou__mouding_skillcount"))
  if n == 0 then
    room:setPlayerMark(player, "rfenghou__mouding_record", 0)
  else
    local cards = table.filter(room.discard_pile, function (id)
      return Fk:getCardById(id):isCommonTrick()
    end)
    if n > #cards then
      room:setPlayerMark(player, "rfenghou__mouding_record", 0)
    else
      room:setPlayerMark(player, "rfenghou__mouding_record", Fk:getCardById(cards[n]).name)
    end
  end
  if not card_only then
    if player:getMark("rfenghou__mouding_skills") ~= 0 then
      room:handleAddLoseSkills(player, "-"..table.concat(player:getMark("rfenghou__mouding_skills"), "|-"), nil, false, false)
      room:setPlayerMark(player, "rfenghou__mouding_skills", 0)
    end
    if n > 0 and n <= #room.general_pile then
      local general = room.general_pile[n]
      local skills = {}
      for _, s in ipairs(Fk.generals[general]:getSkillNameList()) do
        if string.sub(Fk:getDescription(s, "zh_CN"), 7, 12) ~= "技，" and not player:hasSkill(s, true) then
          table.insert(skills, s)
        end
      end
      if #skills > 0 then
        room:setPlayerMark(player, "rfenghou__mouding_skills", skills)
        room:handleAddLoseSkills(player, table.concat(skills, "|"), nil, false, false)
      end
    end
  end
end
local mouding_record = fk.CreateTriggerSkill{
  name = "#rfenghou__mouding_record",

  refresh_events = {fk.AfterCardUseDeclared, fk.AfterSkillEffect, fk.StartPlayCard, fk.HandleAskForPlayCard},
  can_refresh = function (self, event, target, player, data)
    if player:hasSkill(self, true) then
      if event == fk.AfterCardUseDeclared then
        return target == player and data.card.type == Card.TypeTrick
      elseif event == fk.AfterSkillEffect then
        return target == player and data:isPlayerSkill()  and player:hasSkill(data, true) and
          data ~= mouding
      elseif event == fk.StartPlayCard then
        return target == player
      elseif event == fk.HandleAskForPlayCard then
        return data.eventData and Exppattern:Parse(data.pattern):match(Fk:cloneCard("nullification"))
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardUseDeclared then
      room:addPlayerMark(player, "rfenghou__xingbian_trickcount", 1)
      MoudingClear(player)
    elseif event == fk.AfterSkillEffect then
      room:addPlayerMark(player, "rfenghou__mouding_skillcount", 1)
      MoudingClear(player)
    elseif event == fk.StartPlayCard then
      MoudingClear(player, true)
    elseif event == fk.HandleAskForPlayCard then
      MoudingClear(player, true)
    end
  end,
}
local xingbian = fk.CreateTriggerSkill{
  name = "rfenghou__xingbian",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.EventPhaseChanging, fk.EventPhaseProceeding},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.EventPhaseChanging then
        return data.from == Player.Judge and
          table.find(player.room.alive_players, function (p)
            return p:hasDelayedTrick("lightning")
          end)
      elseif event == fk.EventPhaseProceeding then
        return player.phase == Player.Judge and
          not table.find(player.room.alive_players, function (p)
            return p:hasDelayedTrick("lightning")
          end)
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    if event == fk.EventPhaseChanging then
      room:notifySkillInvoked(player, self.name, "special")
      room:addPlayerMark(player, "rfenghou__xingbian_count", 1)
      room:endTurn()
      room:delay(200)
    elseif event == fk.EventPhaseProceeding then
      room:notifySkillInvoked(player, self.name, "defensive")
      if player:isWounded() then
        room:recover({
          who = player,
          num = 1,
          recoverBy = player,
          skillName = self.name,
        })
      end
      player._phase_end = true
    end
  end,
}
local xingbian_filter = fk.CreateFilterSkill{
  name = "#rfenghou__xingbian_filter",
  card_filter = function(self, to_select, player, isJudgeEvent)
    return isJudgeEvent and table.find(Fk:currentRoom().alive_players, function (p)
      return p:getMark("rfenghou__xingbian_count") > 0 and p:getMark("rfenghou__xingbian_count") % 20 == 0
    end)
  end,
  view_as = function(self, to_select, player)
    return Fk:cloneCard(to_select.name, Card.Spade, 3)
  end,
}
local xingbian_invalidity = fk.CreateInvaliditySkill {
  name = "#rfenghou__xingbian_invalidity",
  invalidity_func = function(self, from, skill)
    return skill:isPlayerSkill(from) and not string.find(skill.name, "rfenghou__xingbian") and
    table.find(Fk:currentRoom().alive_players, function (p)
      return p:hasSkill(xingbian)
    end) and
    table.find(Fk:currentRoom().alive_players, function (p)
      return p:hasDelayedTrick("lightning")
    end)
  end
}
mouding:addRelatedSkill(mouding_record)
xingbian:addRelatedSkill(xingbian_filter)
xingbian:addRelatedSkill(xingbian_invalidity)
wangling:addSkill(mouding)
wangling:addSkill(xingbian)
Fk:loadTranslationTable{
  ["rfenghou__wangling"] = "王淩",
  ["#rfenghou__wangling"] = "皑潮不兴",
  ["illustrator:rfenghou__wangling"] = "恶童",
  ["designer:rfenghou__wangling"] = "zzcclll朱苦力",

  ["rfenghou__mouding"] = "谋定",
  [":rfenghou__mouding"] = "你可以将一张锦囊牌当弃牌堆的第X张普通锦囊牌使用，你可以发动武将牌堆第X张武将牌上的一个无标签技能"..
  "（X为你使用锦囊牌与发动其他技能的次数之差）。",
  ["rfenghou__xingbian"] = "星变",
  [":rfenghou__xingbian"] = "锁定技，若场上没有【闪电】，你的判定阶段改为回复1点体力；否则所有角色除〖星变〗以外的技能失效，且于判定阶段结束后"..
  "结束当前回合。",

  ["#rfenghou__mouding"] = "谋定：你可以将一张锦囊牌当【%arg】使用",
  ["#rfenghou__xingbian_filter"] = "星变",
  ["$rfenghou__mouding1"] = "社稷之重，可倾山河湖海，负肩当驱千里。",
  ["$rfenghou__mouding2"] = "乱臣如逆潮当空，臣宁舍残躯以遏浊流。",
  ["$rfenghou__xingbian1"] = "星夜向往，斗中显贵。",
  ["$rfenghou__xingbian2"] = "荧惑冲斗，吾等大事可谋。",
  ["~rfenghou__wangling"] = "贾梁道，凌固忠于魏之社稷！",
}

local caoying = General:new(extension, "rfenghou__caoying", "wei", 4, 4, General.Female)
local jianyingc = fk.CreateActiveSkill{
  name = "rfenghou__jianyingc",
  anim_type = "control",
  card_num = 1,
  target_num = 1,
  prompt = "#rfenghou__jianyingc",
  can_use = function(self, player)
    return player:getMark("@@rfenghou__jianyingc-turn") == 0
  end,
  card_filter = Util.TrueFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:addTableMark(player, "rfenghou__jianyingc-turn", effect.cards[1])
    room:moveCardTo(effect.cards, Card.PlayerHand, target, fk.ReasonGive, self.name, nil, false, player.id)
    if player.dead or target.dead or target:isNude() then return end
    local cards = room:askForCardsChosen(player, target, math.min(2, #target:getCardIds("he")), 2, "he", self.name,
      "#rfenghou__jianyingc-discard::"..target.id)
    room:throwCard(cards, self.name, target, player)
  end,
}
local jianyingc_delay = fk.CreateTriggerSkill{
  name = "#rfenghou__jianyingc_delay",
  mute = true,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:getMark("rfenghou__jianyingc-turn") == 0 or player.dead then return end
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard and move.skillName == "rfenghou__jianyingc" then
        for _, info in ipairs(move.moveInfo) do
          if table.contains(player:getTableMark("rfenghou__jianyingc-turn"), info.cardId) or
            Fk:getCardById(info.cardId).type == Card.TypeEquip or
            (Fk:getCardById(info.cardId).trueName == "slash" and table.contains(player.room.discard_pile, info.cardId)) then
            return true
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("rfenghou__jianyingc-turn")
    local cards = {}
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard and move.skillName == "rfenghou__jianyingc" then
        for _, info in ipairs(move.moveInfo) do
          if Fk:getCardById(info.cardId).type == Card.TypeEquip or table.contains(mark, info.cardId) then
            table.removeOne(mark, info.cardId)
            room:setPlayerMark(player, "@@rfenghou__jianyingc-turn", 1)
          end
          if Fk:getCardById(info.cardId).trueName == "slash" and table.contains(room.discard_pile, info.cardId) then
            table.insertIfNeed(cards, info.cardId)
          end
        end
      end
    end
    room:setPlayerMark(player, "rfenghou__jianyingc-turn", mark)
    cards = U.moveCardsHoldingAreaCheck(room, cards)
    if #cards > 0 then
      room:delay(1000)
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, "rfenghou__jianyingc", nil, true, player.id)
    end
  end,
}
local jueyun = fk.CreateTriggerSkill{
  name = "rfenghou__jueyun",
  anim_type = "control",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn)
      if turn_event == nil or turn_event.data[1] ~= player then return end
      local dat = {}
      for _, move in ipairs(data) do
        if move.from and move.from ~= player.id then
          local to = player.room:getPlayerById(move.from)
          if to:getHandcardNum() < player:getHandcardNum() and not to.dead and
            not table.contains(player:getTableMark("rfenghou__jueyun-turn"), to.id) then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand then
                dat[string.format("%.0f", move.from)] = (dat[string.format("%.0f", move.from)] or 0) + 1
              end
            end
          end
        end
      end
      local targets = {}
      for _, p in ipairs(player.room:getOtherPlayers(player)) do
        if dat[string.format("%.0f", p.id)] and
          p:getHandcardNum() + dat[string.format("%.0f", p.id)] >= player:getHandcardNum() then
          table.insert(targets, p.id)
        end
      end
      if #targets > 0 then
        self.cost_data = targets
        return true
      end
    end
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    local targets = table.simpleClone(self.cost_data)
    room:sortPlayersByAction(targets)
    local mark = player:getTableMark("rfenghou__jueyun-turn")
    table.insertTable(mark, targets)
    room:setPlayerMark(player, "rfenghou__jueyun-turn", mark)
    for _, id in ipairs(targets) do
      if not player:hasSkill(self) then break end
      local p = room:getPlayerById(id)
      if not p.dead then
        self:doCost(event, p, player, data)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#rfenghou__jueyun-invoke::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})

    local req = Request:new({player, target}, "AskForChoice")
    req.focus_text = self.name
    req.receive_decode = false
    local choices1 = {"rfenghou__jueyun11", "rfenghou__jueyun21", "rfenghou__jueyun31"}
    req:setData(player, {choices1, choices1, self.name, "#rfenghou__jueyun-choice::"..target.id})
    req:setDefaultReply(player, table.random(choices1))
    local choices2 = {"rfenghou__jueyun12", "rfenghou__jueyun22", "rfenghou__jueyun32"}
    req:setData(target, {choices2, choices2, self.name, "#rfenghou__jueyun-choice::"..player.id})
    req:setDefaultReply(target, table.random(choices2))
    req:ask()

    for _, p in ipairs({player, target}) do
      room:sendLog{
        type = "#Choice",
        from = p.id,
        arg = req:getResult(p)[17],
        toast = true,
      }
    end
    local result = {0, 0, 0}
    local index = tonumber(req:getResult(player)[17])
    result[index] = result[index] + 1
    index = tonumber(req:getResult(target)[17])
    result[index] = result[index] + 1
    if table.contains(result, 2) then
      index = table.indexOf(result, 2)
    else
      index = table.indexOf(result, 0)
    end
    if index == 1 then
      player:broadcastSkillInvoke(self.name, 1)
      room:addPlayerMark(player, MarkEnum.SlashResidue.."-phase", 1)
      --[[room:damage{
        from = player,
        to = target,
        damage = 1,
        skillName = self.name,
      }]]--
    elseif index == 2 then
      player:broadcastSkillInvoke(self.name, 2)
      player:drawCards(2, self.name)
    elseif index == 3 then
      player:broadcastSkillInvoke(self.name, 3)
      room:setPlayerMark(target, "@@rfenghou__jueyun-turn", 1)
    end
  end,
}
local jueyun_prohibit = fk.CreateProhibitSkill{
  name = "#rfenghou__jueyun_prohibit",
  prohibit_use = function(self, player, card)
    return card and player:getMark("@@rfenghou__jueyun-turn") > 0
  end,
}
jianyingc:addRelatedSkill(jianyingc_delay)
jueyun:addRelatedSkill(jueyun_prohibit)
caoying:addSkill(jianyingc)
caoying:addSkill(jueyun)
Fk:loadTranslationTable{
  ["rfenghou__caoying"] = "曹婴",
  ["#rfenghou__caoying"] = "龙凄凤翥",
  ["illustrator:rfenghou__caoying"] = "刘小狼",
  ["designer:rfenghou__caoying"] = "末页",

  ["rfenghou__jianyingc"] = "间影",
  [":rfenghou__jianyingc"] = "出牌阶段，你可以交给一名其他角色一张牌，弃置其两张牌，你获得弃置的【杀】，若弃置了装备牌或你本回合以此法"..
  "交出的牌，此技能本回合失效。",
  ["rfenghou__jueyun"] = "攫云",
  [":rfenghou__jueyun"] = "你的回合内，当其他角色本回合首次失去手牌变为手牌数小于你后，你可以与其同时选择一项，"..
  "执行被选择次数唯一最多或最少的一项：1.你此阶段使用【杀】次数上限+1；2.你摸两张牌；3.其本回合不能使用牌。",
  ["#rfenghou__jianyingc"] = "间影：交给一名其他角色一张牌，弃置其两张牌",
  ["@@rfenghou__jianyingc-turn"] = "间影失效",
  ["#rfenghou__jianyingc-discard"] = "间影：弃置%dest两张牌，你获得其中的杀，若弃置了装备牌或你交出的牌，此技能本回合失效",
  ["#rfenghou__jianyingc_delay"] = "间影",
  ["#rfenghou__jueyun-invoke"] = "攫云：是否对 %dest 发动“攫云”，与其同时选择选项？",
  ["#rfenghou__jueyun-choice"] = "攫云：与 %dest 同时选择一项，执行被选择次数唯一最多或最少的一项",
  --["rfenghou__jueyun11"] = "对其造成1点伤害",
  ["rfenghou__jueyun11"] = "此阶段使用【杀】次数+1",
  ["rfenghou__jueyun21"] = "你摸两张牌",
  ["rfenghou__jueyun31"] = "其本回合不能使用牌",
  --["rfenghou__jueyun12"] = "其对你造成1点伤害",
  ["rfenghou__jueyun12"] = "其此阶段使用【杀】次数+1",
  ["rfenghou__jueyun22"] = "其摸两张牌",
  ["rfenghou__jueyun32"] = "你本回合不能使用牌",
  ["#rfenghou__jueyun-quest"] = "%from 选择第 %arg 项",
  ["@@rfenghou__jueyun-turn"] = "禁止使用牌",

  ["$rfenghou__jianyingc1"] = "你还是太弱了。",
  ["$rfenghou__jianyingc2"] = "埋伏在此，就等将军你来了。",
  ["$rfenghou__jueyun1"] = "枭雄佑护，祖父遗志，我定继承！",
  ["$rfenghou__jueyun2"] = "将军，这些还是留给小女吧！",
  ["$rfenghou__jueyun3"] = "你这点小心思，我还会猜不透？",
  ["~rfenghou__caoying"] = "外敌易御，内奸难挡。",
}


local caozhao = General:new(extension, "rfenghou__caozhao", "wei", 4)

local xixi = fk.CreateActiveSkill{
  name = "rfenghou__xixi",
  mute = true,
  card_num = 0,
  target_num = 1,
  prompt = "#rfenghou__xixi",
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    local to = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0 and Self.id ~= to_select
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    player:broadcastSkillInvoke(self.name, 1)
    room:notifySkillInvoked(player, self.name, "offensive")
    room:recover { num = 1, skillName = self.name, who = to, recoverBy = player }
    if player.dead or to.dead then return end
    local card = Fk:cloneCard("duel")
    card.skillName = self.name
    if player:prohibitUse(card) or player:isProhibited(to, card) then return end
    room:useCard{from = player.id, tos = {{to.id}}, card = card, additionalDamage = 4,
    extra_data = {rfenghou__xixi_tos = {player.id, to.id}  }}
  end,
}

local rfenghou__xixi_trigger = fk.CreateTriggerSkill{
  name = "#rfenghou__xixi_trigger",
  mute = true,
  events = { fk.AskForCardResponse, fk.CardResponding },
  can_trigger = function (self, event, target, player, data)
    if target ~= player then return end
    if event == fk.AskForCardResponse then
      if data.cardName == "slash" then
        local effect = data.eventData
        return effect and effect.card and table.contains(effect.card.skillNames, xixi.name)
        and effect.extra_data
        -- 限制只有自己和最初的目标才能如此响应……
        and table.contains(effect.extra_data.rfenghou__xixi_tos or {}, player.id)
        and effect.additionalDamage and effect.additionalDamage >= 0
      end
    else
      if data.card.trueName == "slash" then
        local effect = data.responseToEvent
        return effect and effect.card and table.contains(effect.card.skillNames, xixi.name)
        and effect.additionalDamage and effect.additionalDamage >= 0
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AskForCardResponse then
      local effect = data.eventData
      effect.extra_data = effect.extra_data or {}
      effect.extra_data.rfenghou__xixiDraw = effect.extra_data.rfenghou__xixiDraw or {}
      local drawer = effect.extra_data.rfenghou__xixiDraw
      local choices = {"draw2"}
      if #table.filter(player:getCardIds("he"), function(id) return not player:prohibitDiscard(id) end) > 1 then
        table.insert(choices, "rfenghou__xixi_discard")
      end
      if #choices == 0 then return end
      table.insert(choices, "Cancel")
      local choice = room:askForChoice(player, choices, xixi.name, "#rfenghou__xixi-choice")
      if choice == "Cancel" then return end
      if choice == "draw2" then
        player:broadcastSkillInvoke("rfenghou__xixi", table.random({2, 3}))
        player:drawCards(2, xixi.name)
        table.insertIfNeed(drawer, player.id)
        if #drawer == 2 then
          effect.disresponsiveList = effect.disresponsiveList or {}
          table.insertIfNeed(effect.disresponsiveList, effect.from)
          table.insertIfNeed(effect.disresponsiveList, effect.to)
        end
      else
        player:broadcastSkillInvoke("rfenghou__xixi", table.random({4, 5}))
        room:askForDiscard(player, 2, 2, true, xixi.name, false)
      end
      data.result = Fk:cloneCard("slash")
      data.result.skillName = xixi.name
      return true
    else
      player:broadcastSkillInvoke("rfenghou__xixi", table.random({6, 7, 8}))
      local effect = data.responseToEvent
      effect.additionalDamage = effect.additionalDamage - 1
    end
  end,
}
xixi:addRelatedSkill(rfenghou__xixi_trigger)
caozhao:addSkill(xixi)
Fk:loadTranslationTable{
  ["rfenghou__caozhao"] = "曹肇",
  ["#rfenghou__caozhao"] = "虎裾龙袢",
  ["illustrator:rfenghou__caozhao"] = "匠人绘",
  ["designer:rfenghou__caozhao"] = "yyuaN",

  ["rfenghou__xixi"] = "犀嬉",
  [":rfenghou__xixi"] = "出牌阶段限一次，你可令一名其他角色回复1点体力，视为对其使用伤害基数为5、被【杀】响应后伤害-1的【决斗】，"..
  "你与其均可摸或弃两张牌视为打出【杀】响应之，均选择摸牌后，均不能再响应。",
  ["#rfenghou__xixi"] = "犀嬉：令一名其他角色回复体力，视为对其用【决斗】！",
  ["#rfenghou__xixi-choice"] = "犀嬉：你可以摸两张牌或弃置两张牌视为响应此【决斗】",
  ["#rfenghou__xixi_trigger"] = "犀嬉",
  ["rfenghou__xixi_discard"] = "弃两张牌",

  ["$rfenghou__xixi1"]= "吾既身受宠遇，敢不为君分忧？",
  ["$rfenghou__xixi2"]= "君既赌输，理当再脱一件！",
  ["$rfenghou__xixi3"]= "以侯归第，终败于其！",
  ["$rfenghou__xixi4"]= "君若如此，让我如何见人？",
  ["$rfenghou__xixi5"]= "望陛下听臣忠言，勿信资等无知之论！",
  ["$rfenghou__xixi6"]= "此亦久矣，岂能复几！",
  ["$rfenghou__xixi7"]= "臣得君上垂青，已是此生之幸。",
  ["$rfenghou__xixi8"]= "前朝王莽之乱，可为今史之鉴。",
  ["~rfenghou__caozhao"] = "虽极荣宠，亦有尽时...",
}

local bailingyun = General:new(extension, "rfenghou__bailingyun", "wei", 3, 3, General.Female)
local rouke = fk.CreateTriggerSkill{
  name = "rfenghou__rouke",
  anim_type = "support",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player and target.phase == Player.Play and not target.dead and
      target:getHandcardNum() > 1 and player:usedSkillTimes(self.name, Player.HistoryRound) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#rfenghou__rouke-invoke::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    local cards = room:askForCardsChosen(player, target, 2, 2, "h", self.name, "#rfenghou__rouke-put::"..target.id)
    room:moveCards{
      ids = cards,
      from = target.id,
      toArea = Card.DrawPile,
      moveReason = fk.ReasonPut,
      skillName = self.name,
      drawPilePosition = 1,
      moveVisible = false,
    }
    if target.dead then return end
    local choice = room:askForChoice(target, {"rfenghou__rouke1", "rfenghou__rouke22:"..player.id}, self.name,
      "#rfenghou__rouke-choice:"..player.id)
    room:sendLog{
      type = "#CommandChoice",  --直接偷军令log
      from = target.id,
      arg = string.sub(choice, 1, 16),
      toast = true,
    }
    if not player.dead and room:askForSkillInvoke(player, self.name, nil, "#rfenghou__rouke-draw::"..target.id) then
      target:drawCards(2, self.name)
    end
    if not target.dead then
      if choice == "rfenghou__rouke1" then
        target:gainAnExtraPhase(Player.Play, true)
      else
        room:setPlayerMark(player, "rfenghou__rouke-turn", target.id)
      end
    end
  end,
}
local rouke_delay = fk.CreateTriggerSkill{
  name = "#rfenghou__rouke_delay",
  anim_type = "support",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:getMark("rfenghou__rouke-turn") == target.id and not target.dead
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    target:drawCards(2, "rfenghou__rouke")
    if not player.dead and not target.dead and not target:isNude() then
      local card = room:askForCard(target, 1, 1, true, "rfenghou__rouke", false, nil, "#rfenghou__rouke-give:"..player.id)
      room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, "rfenghou__rouke", nil, false, target.id)
    end
  end,
}
local mita = fk.CreateTriggerSkill{
  name = "rfenghou__mita",
  anim_type = "masochism",
  events = {fk.Damaged, fk.AskForPeachesDone},
  can_trigger = function(self, event, target, player, data)
    return target == player and ((event == fk.Damaged and player:hasSkill(self)) or
      (event == fk.AskForPeachesDone and player:hasSkill(self, false, true) and player.hp <= 0)) and
      table.find(player.room.alive_players, function (p)
        return p:inMyAttackRange(player) and not p:isNude()
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p)
      return p:inMyAttackRange(player) and not p:isNude()
    end)
    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 9,
      "#rfenghou__mita-choose", self.name, true)
    if #tos > 0 then
      room:sortPlayersByAction(tos)
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dat, cards = {}, {}
    for _, id in ipairs(self.cost_data.tos) do
      local p = room:getPlayerById(id)
      local card = room:askForCardChosen(player, p, "he", self.name, "#rfenghou__mita-ask::"..p.id)
      table.insert(dat, {id, card})
      table.insert(cards, card)
    end
    if player:isWounded() then
      local targets = room.alive_players
      if event == fk.AskForPeachesDone then
        targets = room:getOtherPlayers(player)
      end
      local result = room:askForYiji(player, cards, targets, self.name, 0, player:getLostHp(),
        "#rfenghou__mita-give:::"..player:getLostHp(), cards)
      if player.dead then return end
      for _, ids in pairs(result) do
        if #ids > 0 then
          for _, id in ipairs(ids) do
            table.removeOne(cards, id)
          end
        end
      end
    end
    if #cards > 0 then
      local new_cards = {}
      for _, info in ipairs(dat) do
        if table.contains(cards, info[2]) and table.contains(room:getPlayerById(info[1]):getCardIds("h"), info[2]) then
          table.insert(new_cards, info[2])
        end
      end
      if #new_cards == 0 then return end
      local result = room:askForGuanxing(player, new_cards, nil, {0, 0}, self.name, true, {"Bottom", ""})
      local moves = {}
      for _, id in ipairs(result.top) do
        table.insert(moves, {
          ids = {id},
          toArea = Card.DrawPile,
          moveReason = fk.ReasonPut,
          skillName = self.name,
          drawPilePosition = -1,
          moveVisible = false,
        })
      end
      room:moveCards(table.unpack(moves))
    end
  end,
}
rouke:addRelatedSkill(rouke_delay)
bailingyun:addSkill(rouke)
bailingyun:addSkill(mita)
Fk:loadTranslationTable{
  ["rfenghou__bailingyun"] = "柏灵筠",
  ["#rfenghou__bailingyun"] = "君心妾心",
  ["designer:rfenghou__bailingyun"] = "张让",
  ["illustrator:rfenghou__bailingyun"] = "黯荧岛",

  ["rfenghou__rouke"] = "柔克",
  [":rfenghou__rouke"] = "每轮限一次，其他角色的出牌阶段结束时，你可以将其两张手牌置于牌堆顶，并令其选择一项：1.执行一个出牌阶段；"..
  "2.本回合结束时从牌堆底摸两张牌并交给你一张牌。选择完成后，你可以令其摸两张牌。",
  ["rfenghou__mita"] = "靡它",
  [":rfenghou__mita"] = "当你受到伤害后或死亡前，你可以将任意名攻击范围内包含你的角色各一张牌以任意顺序置于牌堆底；你每损失1点体力，"..
  "可以先分配其中一张牌。",
  ["#rfenghou__rouke-invoke"] = "柔克：是否将 %dest 两张手牌置于牌堆顶，令其选择一项？",
  ["#rfenghou__rouke-put"] = "柔克：将 %dest 的两张手牌置于牌堆顶",
  ["rfenghou__rouke1"] = "执行一个出牌阶段",
  ["rfenghou__rouke22"] = "回合结束时摸两张牌并交给 %src 一张牌",
  ["rfenghou__rouke2"] = "回合结束时摸两张牌并交出一张牌",
  ["#rfenghou__rouke-choice"] = "柔克：选择 %src 令你执行的一项",
  ["#rfenghou__rouke-draw"] = "柔克：是否令 %dest 摸两张牌？",
  ["#rfenghou__rouke_delay"] = "柔克",
  ["#rfenghou__rouke-give"] = "柔克：请交给 %src 一张牌",
  ["#rfenghou__mita-choose"] = "靡它：你可以将其中任意名角色各一张牌置于牌堆底，你每损失1点体力可以分配其中一张",
  ["#rfenghou__mita-ask"] = "靡它：选择 %dest 的一张牌",
  ["#rfenghou__mita-give"] = "靡它：你可以分配其中%arg张牌，其余牌置于牌堆底",

  ["$rfenghou__rouke1"]= "我之私君者，爱也，君之私我者，情也。",
  ["$rfenghou__rouke2"]= "愿得仲达之心，山河不改，白首不移。",
  ["$rfenghou__mita1"] = "妾本西来之孤蓬，不可负王，亦不可负卿。",
  ["$rfenghou__mita2"] = "我心悦君，愿为卿而死，愿为君刀俎。",
  ["~rfenghou__bailingyun"] = "我叹那落叶知秋，难归故里。",
}

local moqiongshu = General:new(extension, "rfenghou__moqiongshu", "wei", 3, 3, General.Female)

local rfenghou__huayi = fk.CreateActiveSkill{
  name = "rfenghou__huayi",
  anim_type = "support",
  target_num = 1,
  prompt = "#rfenghou__huayi",
  card_filter = function(self, to_select, selected)
    return #selected < 2 and Fk:getCardById(to_select).type == Card.TypeEquip
    and (#selected == 0 or Fk:getCardById(to_select).color ~= Fk:getCardById(selected[1]).color)
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    local to = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0 and to:hasEmptyEquipSlot(Card.SubtypeTreasure) and (#selected_cards == 2 or #selected_cards == 0)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    if #effect.cards > 0 then
      room:throwCard(effect.cards, self.name, player, player)
    else
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".|.|diamond,heart",
      }
      room:judge(judge)
      if judge.card.color ~= Card.Red then
        return
      end
    end
    local to = room:getPlayerById(effect.tos[1])
    if not to:hasEmptyEquipSlot(Card.SubtypeTreasure) or to.dead then return end
    local cardId
    local targets = table.filter(room:getOtherPlayers(to, false), function (p)
      return table.find(p:getCardIds("e"), function(id) return Fk:getCardById(id).name == "cicada_temples" end)
    end)
    if #targets > 0 then
      local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#rfenghou__huayi-from:"..to.id, self.name, true)
      if #tos > 0 then
        cardId = table.find(room:getPlayerById(tos[1]):getCardIds("e"), function(id) return Fk:getCardById(id).name == "cicada_temples" end)
      end
    end
    if not cardId then
      cardId = table.find(room.void, function(id) return Fk:getCardById(id).name == "cicada_temples" end)
      if not cardId then
        cardId = room:printCard("cicada_temples", Card.Club, 12).id
      end
    end
    if Fk:getCardById(cardId):getMark(MarkEnum.DestructIntoDiscard) == 0 then
      room:setCardMark(Fk:getCardById(cardId), MarkEnum.DestructIntoDiscard, 1)
    end
    room:moveCardIntoEquip(to, cardId, self.name, false, player)
  end,
}

local rfenghou__huayi_trigger = fk.CreateTriggerSkill{
  name = "#rfenghou__huayi_trigger",
  anim_type = "drawcard",
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:hasEmptyEquipSlot(Card.SubtypeTreasure) then
      local cardId = table.find(room.void, function(id) return Fk:getCardById(id).name == "cicada_temples" end)
      if not cardId then
        cardId = room:printCard("cicada_temples", Card.Club, 12).id
      end
      if Fk:getCardById(cardId):getMark(MarkEnum.DestructIntoDiscard) == 0 then
        room:setCardMark(Fk:getCardById(cardId), MarkEnum.DestructIntoDiscard, 1)
      end
      room:moveCardIntoEquip(player, cardId, self.name, false, player)
    end
  end,
}
rfenghou__huayi:addRelatedSkill(rfenghou__huayi_trigger)

moqiongshu:addSkill(rfenghou__huayi)

local zhengxiao = fk.CreateTriggerSkill{
  name = "rfenghou__zhengxiao",
  anim_type = "drawcard",
  attached_skill_name = "rfenghou__zhengxiao_other&",
  events = {fk.CardUseFinished, fk.CardRespondFinished},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.card.name == "jink" and
    type(data.card:getMark(self.name)) == "table" and data.card:getMark(self.name).owner == player.id
  end,
  on_cost = function (self, event, target, player, data)
    local to = player.room:getPlayerById(data.card:getMark(self.name).from)
    if not to.dead and player.room:askForSkillInvoke(player, self.name, nil, "#rfenghou__zhengxiao-choice:"..to.id) then
      self.cost_data = {tos = {to.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.card:getMark(self.name).from)
    local judge = {
      who = to,
      reason = self.name,
      pattern = ".|.|^nosuit",
    }
    room:judge(judge)
    if not to.dead then
      if judge.card.color == Card.Red then
        room:recover { num = 1, skillName = self.name, who = to, recoverBy = player }
      elseif judge.card.color == Card.Black then
        to:drawCards(2, self.name)
      end
    end
  end,
}
moqiongshu:addSkill(zhengxiao)

local rfenghou__zhengxiao_other = fk.CreateViewAsSkill{
  name = "rfenghou__zhengxiao_other&",
  anim_type = "defensive",
  prompt = "#rfenghou__zhengxiao",
  pattern = "jink",
  card_filter = function (self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    local card = Fk:cloneCard("jink")
    card:setMark(self.name, cards[1])
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local give = use.card:getMark(self.name)
    if give == 0 then return "" end
    local targets = table.map(table.filter(room.alive_players, function (p)
      return p ~= player and p:hasSkill(zhengxiao)
    end), Util.IdMapper)
    if #targets == 0 then return "" end
    if #targets > 1 then
      targets = room:askForChoosePlayers(player, targets, 1, 1, "#rfenghou__zhengxiao-give", self.name, false, true)
    end
    local ownerId = targets[1]
    targets = table.map(table.filter(room.alive_players, function (p)
      return p ~= player and table.find(p:getCardIds("e"), function (id) return Fk:getCardById(id).name == "cicada_temples" end)
    end), Util.IdMapper)
    if #targets == 0 then return "" end
    if #targets > 1 then
      targets = room:askForChoosePlayers(player, targets, 1, 1, "#rfenghou__zhengxiao-get", self.name, false, true)
    end
    local from = room:getPlayerById(targets[1])
    local get = table.find(from:getCardIds("e"), function (id) return Fk:getCardById(id).name == "cicada_temples" end)
    -- 打出不能用extra_data加信息
    room:setCardMark(use.card, "rfenghou__zhengxiao", {from = from.id, owner = ownerId})
    room:moveCards({
      from = player.id,
      to = ownerId,
      ids = {give},
      toArea = Card.PlayerHand,
      moveReason = fk.ReasonGive,
      skillName = self.name,
      moveVisible = true,
      proposer = player.id,
    },{
      from = from.id,
      to = player.id,
      ids = {get},
      toArea = Card.PlayerEquip,
      moveReason = fk.ReasonJustMove,
      skillName = self.name,
      moveVisible = true,
      proposer = player.id,
    })
  end,
  enabled_at_response = function(self, player, response)
    if not player:isNude() and (player:hasEmptyEquipSlot(Card.SubtypeTreasure) or #player:getEquipments(Card.SubtypeTreasure) > 0) then
      return table.find(Fk:currentRoom().alive_players, function (p)
        return p ~= player and p:hasSkill(zhengxiao)
      end)
      and
      table.find(Fk:currentRoom().alive_players, function (p)
        return p ~= player and table.find(p:getCardIds("e"), function (id) return Fk:getCardById(id).name == "cicada_temples" end)
      end) ~= nil
    end
  end,
}
Fk:addSkill(rfenghou__zhengxiao_other)

Fk:loadTranslationTable{
  ["rfenghou__moqiongshu"] = "莫琼树",
  ["#rfenghou__moqiongshu"] = "",
  ["designer:rfenghou__moqiongshu"] = "紫乔",
  ["illustrator:rfenghou__moqiongshu"] = "啪啪三国",

  ["rfenghou__huayi"] = "化翼",
  [":rfenghou__huayi"] = "游戏开始时，将<a href='rfenghou__moqiongshu_cicada_temples'>【蝉鬓】</a>置入你的装备区。"..
  "出牌阶段限一次，你可以弃置两张颜色不同的装备牌，或进行一次判定，若为红，将场上或游戏外的一张【蝉鬓】置于一名角色的装备区。",
  ["rfenghou__moqiongshu_cicada_temples"] = "装备牌·宝物（衍生牌） ♣12<br/><b>宝物技能</b>：锁定技，结束阶段，你摸X张牌"..
  "（X为此牌进入你装备区后经过的回合数，至多为3）。此牌进入弃牌堆后销毁。",
  ["#rfenghou__huayi_trigger"] = "化翼",
  ["#rfenghou__huayi"] = "化翼：弃置两张颜色不同的装备牌，或判定若为红，将【蝉鬓】置于一名角色的装备区",
  ["#rfenghou__huayi-from"] = "化翼：你可将一名角色装备区的【蝉鬓】移动给 %src 。“取消”：印一张",
  ["rfenghou__zhengxiao"] = "争效",
  [":rfenghou__zhengxiao"] = "其他角色可以交给你一张装备牌并将场上一张【蝉鬓】移动给其，视为使用或打出一张【闪】，然后你可以令以此法"..
  "失去【蝉鬓】的角色进行判定：红，回复1点体力；黑，摸两张牌。",
  ["#rfenghou__zhengxiao"] = "争效：你可以交给“莫琼树”一张装备牌并将场上【蝉鬓】移动给你，视为转化【闪】",
  ["#rfenghou__zhengxiao-give"] = "争效：将此装备牌交给拥有“争效”的角色",
  ["#rfenghou__zhengxiao-get"] = "争效：将一名其他角色的【蝉鬓】移动给你",
  ["#rfenghou__zhengxiao_trigger"] = "争效",
  ["rfenghou__zhengxiao_other&"] = "争效",
  [":rfenghou__zhengxiao_other&"] = "其他角色可以交给你一张装备牌并将场上一张【蝉鬓】移动给其，视为使用或打出一张【闪】",
  ["#rfenghou__zhengxiao-choice"] = "争效：你可以令 %src 判定：红，回复1点体力；黑，摸两张牌",
}

local caohuan = General:new(extension, "rfenghou__caohuan", "wei", 3)
local anbing = fk.CreateViewAsSkill{
  name = "rfenghou__anbing",
  pattern = "nullification",
  anim_type = "control",
  prompt = "#rfenghou__anbing",
  card_filter = function (self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).suit ~= Card.NoSuit and
      not table.contains(Self:getTableMark("@rfenghou__anbing-round"), Fk:getCardById(to_select):getSuitString(true))
  end,
  view_as = function(self, cards)
    if #cards == 0 then return end
    local card = Fk:cloneCard("nullification")
    card:addSubcard(cards[1])
    card.skillName = self.name
    return card
  end,
  after_use = function (self, player, use)
    if not player.dead and use.responseToEvent and use.responseToEvent.card then
      if use.responseToEvent.card.is_damage_card or use.responseToEvent.card.sub_type == Card.SubtypeDelayedTrick then
        player:drawCards(1, self.name)
        if not player.dead and table.contains({"lightning", "floating_thunder"}, use.responseToEvent.card.trueName) then
          player:drawCards(1, self.name)
        end
      end
    end
  end,
  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function (self, player, response)
    return not response and #player:getTableMark("@rfenghou__anbing-round") < 4
  end,
}
local anbing_trigger = fk.CreateTriggerSkill{
  name = "#rfenghou__anbing_trigger",

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(anbing, true) and #player:getTableMark("@rfenghou__anbing-round") < 4 and
    target == player and
    data.card.suit ~= Card.NoSuit and not table.contains(player:getTableMark("@rfenghou__anbing-round"), data.card:getSuitString(true))
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addTableMark(player, "@rfenghou__anbing-round", data.card:getSuitString(true))
  end,
}
local yiding = fk.CreateTriggerSkill{
  name = "rfenghou__yiding",
  events = {fk.Damaged, fk.TurnEnd},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.Damaged then
        return target == player and #player.room:canMoveCardInBoard() > 0
      elseif event == fk.TurnEnd then
        return player:isWounded() and
          #player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
            for _, move in ipairs(e.data) do
              for _, info in ipairs(move.moveInfo) do
                if (info.fromArea == Card.PlayerEquip or info.fromArea == Card.PlayerJudge)
                  and info.fromArea == move.toArea then
                  return true
                end
              end
            end
          end, Player.HistoryTurn) > 0
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      local tos = room:askForChooseToMoveCardInBoard(player, "#rfenghou__yiding-move", self.name)
      if #tos > 0 then
        self.cost_data = {tos = tos}
        return true
      end
    elseif event == fk.TurnEnd then
      if room:askForSkillInvoke(player, self.name, nil, "#rfenghou__yiding-recover") then
        self.cost_data = nil
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      local targets = table.map(self.cost_data.tos, Util.Id2PlayerMapper)
      room:askForMoveCardInBoard(player, targets[1], targets[2], self.name)
    elseif event == fk.TurnEnd then
      room:recover{
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      }
    end
  end,
}
local yuanwang = fk.CreateViewAsSkill{
  name = "rfenghou__yuanwang$",
  pattern = "lightning",
  prompt = "#rfenghou__yuanwang",
  card_filter = function (self, to_select, selected)
    return #selected == 0
  end,
  view_as = function(self, cards)
    if #cards == 0 then return end
    local card = Fk:cloneCard("lightning")
    card:addSubcard(cards[1])
    card.skillName = self.name
    return card
  end,
  after_use = function (self, player, use)
    if not player.dead and use.responseToEvent and use.responseToEvent.card then
      if use.responseToEvent.card.is_damage_card or use.responseToEvent.card.sub_type == Card.SubtypeDelayedTrick then
        player:drawCards(1, self.name)
        if not player.dead and table.contains({"lightning", "floating_thunder"}, use.responseToEvent.card.trueName) then
          player:drawCards(1, self.name)
        end
      end
    end
  end,
  enabled_at_play = function (self, player)
    return table.find(Fk:currentRoom().alive_players, function (p)
      return p.kingdom == "wei" and p.role == "loyalist"
    end) or
    table.find(Fk:currentRoom().alive_players, function (p)
      return table.contains({"wangling", "guanqiujian", "zhugedan", "simafu"}, Fk.generals[p.general].trueName)
    end)
  end,
  enabled_at_response = function (self, player, response)
    if response then return end
    return table.find(Fk:currentRoom().alive_players, function (p)
      return p.kingdom == "wei" and p.role == "loyalist"
    end) or
    table.find(Fk:currentRoom().alive_players, function (p)
      return table.contains({"wangling", "guanqiujian", "zhugedan", "simafu"}, Fk.generals[p.general].trueName)
    end)
  end,
}
anbing:addRelatedSkill(anbing_trigger)
caohuan:addSkill(anbing)
caohuan:addSkill(yiding)
caohuan:addSkill(yuanwang)
Fk:loadTranslationTable{
  ["rfenghou__caohuan"] = "曹奂",
  ["#rfenghou__caohuan"] = "盈洼鸣潮",
  ["designer:rfenghou__caohuan"] = "黄泉",
  ["illustrator:rfenghou__caohuan"] = "",

  ["rfenghou__anbing"] = "按柄",
  [":rfenghou__anbing"] = "你可以将一张你本轮未使用过的花色的牌当【无懈可击】使用；若抵消了伤害牌或延时牌，你摸一张牌；若均满足，你再摸一张牌。",
  ["@rfenghou__anbing-round"] = "按柄",
  ["#rfenghou__anbing"] = "按柄：将一张你本轮未使用过的花色的牌当【无懈可击】使用",

  ["rfenghou__yiding"] = "易鼎",
  [":rfenghou__yiding"] = "你受到伤害后，你可以移动场上一张牌；场上有牌移动过的回合结束时，你可以回复1点体力。",
  ["#rfenghou__yiding-move"] = "易鼎：你可以移动场上一张牌",
  ["#rfenghou__yiding-recover"] = "易鼎：是否回复1点体力？",

  ["rfenghou__yuanwang"] = "援王",
  [":rfenghou__yuanwang"] = "主公技，当大魏忠臣在场时，你可以将一张牌当【闪电】使用！",
  ["#rfenghou__yuanwang"] = "援王：你可以将一张牌当【闪电】使用！",
}


local erzhurong = General:new(extension, "rfenghou__erzhurong", "wei", 4)

local jiangbing = fk.CreateViewAsSkill{
  name = "rfenghou__jiangbing",
  mute = true,
  pattern = "collateral",
  prompt = "#rfenghou__jiangbing",
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local c = Fk:cloneCard("collateral")
    c.skillName = self.name
    return c
  end,
  before_use = function(self, player, use)
    player:broadcastSkillInvoke(self.name)
    player.room:notifySkillInvoked(player, self.name, player:getMark("@@rfenghou__jiangbing") == 0 and "control" or "big")
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 or player:getMark("@@rfenghou__jiangbing") == 0
  end,
  enabled_at_response = Util.FalseFunc,
  
  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@@rfenghou__jiangbing", 0)
  end,
}

local jiangbing_trigger = fk.CreateTriggerSkill{
  name = "#rfenghou__jiangbing_trigger",
  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(jiangbing, true) and player:getMark("@@rfenghou__jiangbing") == 0 then
      if table.find(data, function(move) return
        table.find(move.moveInfo, function(info) return info.fromArea == Card.PlayerEquip or info.fromArea == Card.PlayerJudge end)
      end) then
        local e = player.room.logic:getCurrentEvent()
        if e.parent and e.parent.parent then
          e = e.parent.parent
          if e.event == GameEvent.CardEffect then
            local effect = e.data[1]
            return table.contains(effect.card.skillNames, jiangbing.name)
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player:setSkillUseHistory(jiangbing.name, 0, Player.HistoryGame)
    player.room:setPlayerMark(player, "@@rfenghou__jiangbing", 1)
  end,
}
jiangbing:addRelatedSkill(jiangbing_trigger)

erzhurong:addSkill(jiangbing)

local guojie = fk.CreateActiveSkill{
  name = "rfenghou__guojie",
  mute = true,
  card_num = 0,
  target_num = 0,
  prompt = "#rfenghou__guojie",
  frequency = Skill.Limited,
  card_filter = Util.FalseFunc,
  can_use = function(self, player)
    return (player:usedSkillTimes(self.name, Player.HistoryGame) == 0 or player:getMark("@@rfenghou__jiangbing") == 0)
    and table.find({"h", "e", "j"}, function (flag)
      return #player:getCardIds(flag) > 0 and
      table.every(Fk:currentRoom().alive_players, function(p) return #p:getCardIds(flag) <= #player:getCardIds(flag) end)
    end)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:broadcastSkillInvoke(self.name)
    player.room:notifySkillInvoked(player, self.name, player:getMark("@@rfenghou__jiangbing") == 0 and "control" or "big")
    room:setPlayerMark(player, "rfenghou__guojie-turn", 1)
    room:endTurn()
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@@rfenghou__guojie", 0)
    player.room:setPlayerMark(player, "@$rfenghou__guojie_names", 0)
  end,
  on_acquire = function (self, player, is_start)
    player.room:setPlayerMark(player, "@@rfenghou__guojie", 1)
    local names = {}
    for _, name in ipairs(Fk.all_card_names) do
      local card = Fk:cloneCard(name)
      if card.is_damage_card and not card.is_derived and not table.contains(Fk:currentRoom().disabled_packs, card.package.name) then
        table.insert(names, name)
      end
    end
    player.room:setPlayerMark(player, "@$rfenghou__guojie_names", names)
  end,
}

local guojie_trigger = fk.CreateTriggerSkill{
  name = "#rfenghou__guojie_trigger",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:getMark("rfenghou__guojie-turn") ~= 0 and target == player
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local skillName = guojie.name
    for i = 1, 2 do
      if player.dead then break end
      local all_choices = {"rfenghou__guojie_use", "rfenghou__guojie_reset", "rfenghou__guojie_delete"}
      local choices = {}
      local names = table.filter(player:getTableMark("@$rfenghou__guojie_names"), function(name)
        local card = Fk:cloneCard(name)
        card.skillName = skillName
        return player:canUse(card, {bypass_times = true}) and not player:prohibitUse(card)
      end)
      if #names > 0 then
        table.insert(choices, "rfenghou__guojie_use")
      end
      local skills = table.map(table.filter(player.player_skills, function (s)
        return s:isPlayerSkill(player) and s.visible
      end), Util.NameMapper)
      if #skills > 0 then
        table.insert(choices, "rfenghou__guojie_reset")
      end
      local limit = table.filter({"rfenghou__jiangbing", "rfenghou__guojie"}, function (name)
        return player:hasSkill(name, true) and player:getMark("@@"..name) ~= 0
      end)
      if #limit > 0 then
        table.insert(choices, "rfenghou__guojie_delete")
      end
      if #choices == 0 then break end
      local choice = room:askForChoice(player, choices, skillName, "#rfenghou__guojie-choice:::"..i, false, all_choices)
      if choice == "rfenghou__guojie_use" then
        local use = U.askForUseVirtualCard(room, player, names, nil, skillName, nil, true, true, false, true)
        if use then
          local mark = table.filter(player:getTableMark("@$rfenghou__guojie_names"), function(name)
            return Fk:cloneCard(name).trueName ~= use.card.trueName
          end)
          room:setPlayerMark(player, "@$rfenghou__guojie_names", #mark > 0 and mark or 0)
        end
      elseif choice == "rfenghou__guojie_reset" then
        choice = room:askForChoice(player, skills, skillName, "#rfenghou__guojie-reset")
        player:setSkillUseHistory(choice, 0, Player.HistoryGame)
        local skill = Fk.skills[choice]
        if skill then
          skill:onLose(player, false)
          skill:onAcquire(player, false)
        end
      elseif choice == "rfenghou__guojie_delete" then
        choice = room:askForChoice(player, limit, skillName, "#rfenghou__guojie-delete")
        room:setPlayerMark(player, "@@"..choice, 0)
        player:setSkillUseHistory(choice, 0, Player.HistoryGame)
      end
    end
  end,
}
guojie:addRelatedSkill(guojie_trigger)

erzhurong:addSkill(guojie)
AddWinAudio(erzhurong)
Fk:loadTranslationTable{
  ["rfenghou__erzhurong"] = "尔朱荣",
  ["#rfenghou__erzhurong"] = "渊天镇牧",
  ["designer:rfenghou__erzhurong"] = "折翼",
  ["illustrator:rfenghou__erzhurong"] = "伊达未来",
  ["cv:rfenghou__erzhurong"] = "折翼",

  ["rfenghou__jiangbing"] = "将柄",
  [":rfenghou__jiangbing"] = "出牌阶段，你可以视为使用【借刀杀人】，场上牌数因此改变后，此技能标签增加“限定技”。",
  ["@@rfenghou__jiangbing"] = "将柄-限定",
  ["#rfenghou__jiangbing"] = "将柄：视为使用【借刀杀人】",

  ["rfenghou__guojie"] = "国劫",
  [":rfenghou__guojie"] = "限定技，出牌阶段，若你某个区域有牌且为全场最多，你可以结束本回合，然后执行两项或两次一项："..
  "<br>视为使用一张未以此法使用过的伤害类牌；重置一个技能；删除武将牌上一个技能中的“限定技”标签。",
  ["#rfenghou__guojie"] = "国劫:你可以结束本回合，然后执行两项或两次一项",
  ["@@rfenghou__guojie"] = "国劫-限定",
  ["#rfenghou__guojie-choice"] = "国劫：请选择一项！（第 %arg 次，共 2 次）",
  ["rfenghou__guojie_use"] = "视为使用一张未以此法使用过的伤害类牌",
  ["rfenghou__guojie_reset"] = "重置一个技能",
  ["rfenghou__guojie_delete"] = "删除武将牌上一个技能中的“限定技”标签",
  ["@$rfenghou__guojie_names"] = "国劫",
  ["#rfenghou__guojie-reset"] = "国劫：选择你要重置的技能！",
  ["#rfenghou__guojie-delete"] = "国劫：选择一个限定技，删除其“限定技”标签！",
  ["#rfenghou__guojie_trigger"] = "国劫",

  ["$rfenghou__jiangbing1"] = "",
  ["$rfenghou__jiangbing2"] = "",
  ["$rfenghou__guojie1"] = "",
  ["$rfenghou__guojie2"] = "",
  ["$rfenghou__guojie3"] = "",
  ["~rfenghou__erzhurong"] = "",
  ["$rfenghou__erzhurong_win_audio"] = "",
}

local yuanziyou = General:new(extension, "rfenghou__yuanziyou", "wei", 3)

local fuan = fk.CreateTriggerSkill{
  name = "rfenghou__fuan",
  events = {fk.GameStart, fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.GameStart then return true end
      return target == player and (data.card.type == Card.TypeBasic or data.card:isCommonTrick())
      and player:usedSkillTimes(self.name, Player.HistoryRound) == 0
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.GameStart then return true end
    return player.room:askForSkillInvoke(player, self.name, nil, "#rfenghou__fuan-invoke:::"..data.card:toLogString())
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      room:handleAddLoseSkills(player, "rfenghou__jianwang|rfenghou__jianwangg")
      player:setSkillUseHistory("rfenghou__fuan", 0, Player.HistoryRound)
    else
      room:addTableMark(player, "@$rfenghou__fuan-turn", data.card.name)
      if data.toCard then
        data.toCard = nil
      else
        data.tos = {}
      end
      -- 非常麻烦的移动回原处
      local ids = room:getSubcardsByRule(data.card, {Card.Processing})
      if #ids == 0 then return end
      local currentEvent = room.logic:getCurrentEvent()
      local currentUse = currentEvent:findParent(GameEvent.UseCard)
      if not currentUse then return end
      local events = room.logic.event_recorder[GameEvent.MoveCards] or Util.DummyTable
      local moveMap = {}
      for i = #events, 1, -1 do
        local e = events[i]
        if e.id < currentUse.id then break end
        if e.parent == currentUse then
          for _, move in ipairs(e.data) do
            if move.toArea == Card.Processing and move.moveReason == fk.ReasonUse
            and move.from and not room:getPlayerById(move.from).dead then
              for _, info in ipairs(move.moveInfo) do
                if table.removeOne(ids, info.cardId) then
                  moveMap[move.from] = moveMap[move.from] or {}
                  table.insert(moveMap[move.from], info.cardId)
                end
              end
            end
          end
        end
      end
      if next(moveMap) ~= nil then
        local moves = {}
        for pid, moveIds in pairs(moveMap) do
          table.insert(moves, {
            to = pid,
            toArea = Card.PlayerHand,
            moveReason = fk.ReasonJustMove,
            moveVisible = true,
            ids = moveIds,
          })
        end
        room:moveCards(table.unpack(moves))
      end
    end
  end,
}

local furan_delay = fk.CreateTriggerSkill{
  name = "#rfenghou__fuan_delay",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@$rfenghou__fuan-turn") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:invalidateSkill(player, "rfenghou__fuan", "-turn") -- 防止在此结算中再发动
    for _, name in ipairs(player:getTableMark("@$rfenghou__fuan-turn")) do
      U.askForUseVirtualCard(room, player, name, nil, "rfenghou__fuan", nil, true, true, false)
      if player.dead then break end
    end
  end,
}
fuan:addRelatedSkill(furan_delay)
yuanziyou:addSkill(fuan)

local jianwang = fk.CreateActiveSkill{
  name = "rfenghou__jianwang",
  anim_type = "control",
  prompt = "#rfenghou__jianwang",
  frequency = Skill.Limited,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected < ((#Fk:currentRoom().alive_players + 1) // 2) and Self.id ~= to_select
    and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  feasible = function(self, selected, selected_cards)
    return #selected == ((#Fk:currentRoom().alive_players + 1) // 2)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and not player:isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local targets = table.map(effect.tos, Util.Id2PlayerMapper)
    table.insert(targets, player)
    local disc = U.Discussion(player, targets, self.name)
    if player.dead then return end
    local cards = {}
    for pid, result in pairs(disc.results) do
      local p = room:getPlayerById(pid)
      if not p.dead then
        local toCards = result.toCards
        if toCards then
          for _, id in ipairs(toCards) do
            if table.contains(p:getCardIds("h"), id) then
              table.insert(cards, id)
            end
          end
        end
      end
    end
    if #cards == 0 then return end
    local ex_cards = table.filter(cards, function(id) return room:getCardOwner(id) ~= player end)
    local use = U.askForUseRealCard(room, player, cards, tostring(Exppattern{ id = cards }), self.name, "#rfenghou__jianwang-use", {expand_pile = ex_cards})
    if use then
      if use.card:getColorString() == disc.color then
        local currentEvent = room.logic:getCurrentEvent()
        local lastEvent = room.logic:getEventsByRule(GameEvent.SkillEffect, 1, function (e)
          return e.id < currentEvent.id and e.data[2] == player and RUtil.isPlayerSkill(e.data[3])
        end, 1)[1]
        if lastEvent then
          local last = lastEvent.data[3]
          last = (last.main_skill or last)
          RUtil.resetSkill(player, last)
        end
      else
        room:setPlayerMark(player, "@@rfenghou__jianwang", 1)
      end
    end
  end,
}
local jianwang_delay = fk.CreateTriggerSkill{
  name = "#rfenghou__jianwang_delay",
  mute = true,
  events = {fk.SkillEffect},
  can_trigger = function(self, event, target, player, data)
    return player == target and player:getMark("@@rfenghou__jianwang") ~= 0 and RUtil.isPlayerSkill(data)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@rfenghou__jianwang", 0)
    room.logic:getCurrentEvent().parent:addCleaner(function()
      RUtil.resetSkill(player, data.name)
    end)
  end,
}
fuan:addRelatedSkill(jianwang_delay)
yuanziyou:addRelatedSkill(jianwang)

local jianwang2 = fk.CreateActiveSkill{
  name = "rfenghou__jianwangg",
  anim_type = "control",
  prompt = "#rfenghou__jianwang",
  frequency = Skill.Limited,
  card_filter = Util.FalseFunc,
  target_filter = jianwang.targetFilter,
  feasible = jianwang.feasible,
  can_use = jianwang.canUse,
  on_use = jianwang.onUse,
}
Fk:addSkill(jianwang2)

Fk:loadTranslationTable{
  ["rfenghou__yuanziyou"] = "元子攸",
  ["#rfenghou__yuanziyou"] = "九旻寒蝉",
  ["designer:rfenghou__yuanziyou"] = "折翼",
  ["illustrator:rfenghou__yuanziyou"] = "伊达未来",
  ["cv:rfenghou__yuanziyou"] = "折翼",

  ["rfenghou__fuan"] = "伏案",
  [":rfenghou__fuan"] = "游戏开始时，你获得两个独立计算的技能“鉴往”。每轮限一次，你使用基本牌或普通锦囊牌时，可以取消并移回原处，本回合结束后视为使用之。",
  ["#rfenghou__fuan_delay"] = "伏案",
  ["#rfenghou__fuan-invoke"] = "伏案：你可以取消使用%arg，回合结束时视为使用",
  ["@$rfenghou__fuan-turn"] = "伏案",

  ["rfenghou__jianwang"] = "鉴往",
  [":rfenghou__jianwang"] = "限定技，出牌阶段，你可以与半数角色议事（向上取整），然后使用其中一张议事牌，若此牌颜色与议事结果：相同，你令上次发动的技能视为未发动；不同，下次技能发动后视为未发动。",
  ["#rfenghou__jianwang"] = "鉴往:你可以与半数角色议事，然后使用其中一张议事牌",
  ["@@rfenghou__jianwang"] = "鉴往:重置下次",
  ["#rfenghou__jianwang-use"] = "鉴往：使用一张议事牌",
  ["#rfenghou__jianwang_delay"] = "鉴往",

  ["$rfenghou__fuan1"] = "外人亦言，王欲害我，我岂信之？",
  ["$rfenghou__fuan2"] = "竖子若过今日，遂不足制也。",
  ["$rfenghou__fuan3"] = "天命若在，天柱宜自取之。",
  ["$rfenghou__jianwang1"] = "死犹须为，况不必死，朕宁葬乡公之冢，不做陈留一王。",
  ["$rfenghou__jianwang2"] = "伐其魁首，赦其党羽，一如初平未竟之事。",
  ["~rfenghou__yuanziyou"] = "昔来闻死苦，何言身自当。",
}
Fk:loadTranslationTable{
  ["rfenghou__jianwangg"] = "鉴往",
  [":rfenghou__jianwangg"] = Fk:translate(":rfenghou__jianwang", "zh_CN"),
  ["$rfenghou__jianwangg1"] = Fk:translate("$rfenghou__jianwang1", "zh_CN"),
  ["$rfenghou__jianwangg2"] = Fk:translate("$rfenghou__jianwang2", "zh_CN"),
}


local heyan = General:new(extension, "rfenghou__heyan", "wei", 3)
Fk:loadTranslationTable{
  ["rfenghou__heyan"] = "何晏",
  ["#rfenghou__heyan"] = "玉面倾朝",
  ["designer:rfenghou__heyan"] = "祭祀",
  ["cv:rfenghou__heyan"] = "绯瞳",
  ["illustrator:rfenghou__heyan"] = "匪萌十月",
  ["~rfenghou__heyan"] = "青蝇麾不去，白黑自分明。",
}

local xuanshu = fk.CreateTriggerSkill{
  name = "rfenghou__xuanshu",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      return player:getHandcardNum() ~= 4 and data.card.type == Card.TypeBasic
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#rfenghou__xuanshu-invoke:::"..data.card.trueName)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = player:getHandcardNum() - 4
    if x > 0 then
      room:askForDiscard(player, x, x, true, self.name, false)
    else
      player:drawCards(-x, self.name)
    end
    if not player.dead then
      room:setPlayerMark(player, "@rfenghou__xuanshu-turn", data.card.trueName)
    end
  end,
}
local xuanshu_delay = fk.CreateTriggerSkill{
  name = "#rfenghou__xuanshu_delay",
  events = {fk.CardUsing},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@rfenghou__xuanshu-turn") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getMark("@rfenghou__xuanshu-turn")
    room:setPlayerMark(player, "@rfenghou__xuanshu-turn", 0)
    if mark ~= data.card.trueName then
      room:notifySkillInvoked(player, xuanshu.name, "negative")
      local x = player:usedSkillTimes(xuanshu.name)
      room:askForDiscard(player, x, x, true, xuanshu.name, false)
    end
  end,
}
xuanshu:addRelatedSkill(xuanshu_delay)
heyan:addSkill(xuanshu)

Fk:loadTranslationTable{
  ["rfenghou__xuanshu"] = "玄枢",
  [":rfenghou__xuanshu"] = "你使用基本牌后，可以调整手牌数至4，然后若你本回合使用的下一张牌牌名与之不同，你弃置X张牌。（X为此技能本回合发动次数）",
  ["#rfenghou__xuanshu-invoke"] = "玄枢：你可以调整手牌数至4，若你本回合使用下一张牌不为【%arg】，你须弃牌",
  ["#rfenghou__xuanshu_delay"] = "玄枢",
  ["@rfenghou__xuanshu-turn"] = "玄枢",
  ["$rfenghou__xuanshu1"] = "名无名，誉无誉，可拟圣人。",
  ["$rfenghou__xuanshu2"] = "无形、无声、无物、无我，谓之全。",
}

local wenyan = fk.CreateViewAsSkill{
  name = "rfenghou__wenyan",
  pattern = "drugs",
  prompt = "#rfenghou__wenyan",
  card_filter = function (self, to_select, selected, player)
    local card = Fk:getCardById(to_select)
    return #selected == 0 and card.suit ~= Card.NoSuit and
    not table.contains(player:getTableMark("@rfenghou__wenyan-turn"), card:getSuitString(true))
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("drugs")
    card:addSubcards(cards)
    card.skillName = self.name
    return card
  end,
  enabled_at_play = function(self, player)
    return #player:getTableMark("@rfenghou__wenyan-turn") < 4
  end,
  enabled_at_response = Util.FalseFunc,
  on_acquire = function (self, player, is_start)
    if not is_start then
      local room = player.room
      local suits = {}
      room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data[1]
        if use.from == player.id then
          table.insertIfNeed(suits, use.card:getSuitString(true))
        end
      end, Player.HistoryTurn)
      if #suits == 0 then return end
      room:setPlayerMark(player, "@rfenghou__wenyan-turn", suits)
    end
  end,
  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@rfenghou__wenyan-turn", 0)
  end,
}
local wenyan_trigger = fk.CreateTriggerSkill{
  name = "#rfenghou__wenyan_trigger",
  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(wenyan, true) and data.card.suit ~= Card.NoSuit
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addTableMarkIfNeed(player, "@rfenghou__wenyan-turn", data.card:getSuitString(true))
  end,
}
wenyan:addRelatedSkill(wenyan_trigger)
heyan:addSkill(wenyan)

Fk:loadTranslationTable{
  ["rfenghou__wenyan"] = "文焰",
  [":rfenghou__wenyan"] = "你可以将你本回合未使用过的花色的牌当【散】使用。",
  ["#rfenghou__wenyan"] = "文焰：将本回合未使用过的花色当【散】使用。",
  ["@rfenghou__wenyan-turn"] = "文焰",
  ["$rfenghou__wenyan1"] = "六经虽存，固圣人之糠秕！",
  ["$rfenghou__wenyan2"] = "弃精白、怀糟粕，文章尚不能闻，谈何天性？",
}

local ruanyu = General:new(extension, "rfenghou__ruanyu", "wei", 3)
Fk:loadTranslationTable{
  ["rfenghou__ruanyu"] = "阮瑀",
  ["#rfenghou__ruanyu"] = "斐章雅律",
  ["designer:rfenghou__ruanyu"] = "先帝",
  ["illustrator:rfenghou__ruanyu"] = "三道纹",
}

local cijing = fk.CreateTriggerSkill{
  name = "rfenghou__cijing",
  events = {fk.CardUsing},
  mute = true,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.card.is_damage_card and player.phase == Player.Play
    and data.card.number > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = data.card.number
    if num < player:getHandcardNum() then
      player:broadcastSkillInvoke(self.name, 2)
      room:notifySkillInvoked(player, self.name, "negative")
      local x = player:getHandcardNum() - num
      room:askForDiscard(player, x, x, false, self.name, false)
    elseif num == player:getHandcardNum() then
      player:broadcastSkillInvoke(self.name, 1)
      room:notifySkillInvoked(player, self.name, "offensive")
      local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
      "#rfenghou__cijing-damage", self.name, false)
      local to = room:getPlayerById(tos[1])
      room:damage { from = player, to = to, damage = 1, skillName = self.name }
    else
      player:broadcastSkillInvoke(self.name, 1)
      room:notifySkillInvoked(player, self.name, "drawcard")
      player:drawCards(1, self.name)
    end
  end,
}
ruanyu:addSkill(cijing)
Fk:loadTranslationTable{
  ["rfenghou__cijing"] = "辞旌",
  [":rfenghou__cijing"] = "锁定技，出牌阶段，你使用伤害牌时，若此牌点数小于手牌数，你弃置手牌至点数；若等于，你对一名角色造成1点伤害；若大于，你摸一张牌。",
  ["#rfenghou__cijing-damage"] = "辞旌：请造成1点伤害！",

  ["$rfenghou__cijing1"] = "", -- 正面效果
  ["$rfenghou__cijing2"] = "", -- 负面效果
}
ruanyu:addSkill("rfenghou__wenyan")

local ruanji = General:new(extension, "rfenghou__ruanji", "wei", 3)
Fk:loadTranslationTable{
  ["rfenghou__ruanji"] = "阮籍",
  ["#rfenghou__ruanji"] = "命世大贤",
  ["designer:rfenghou__ruanji"] = "先帝",
  ["cv:rfenghou__ruanji"] = "",
  ["illustrator:rfenghou__ruanji"] = "匠人绘",
  ["~rfenghou__ruanji"] = "",
}

local zuiyin = fk.CreateTriggerSkill{
  name = "rfenghou__zuiyin",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardUseDeclared},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      return data.card.name == "analeptic" or data.card.trueName == "drugs"
    end
  end,
  on_cost = function (self, event, target, player, data)
    local name = data.card.name == "analeptic" and "drugs" or "analeptic"
    local x = player:usedSkillTimes(self.name) + 1
    return player.room:askForSkillInvoke(player, self.name, data, "#rfenghou__zuiyin-ask:::"..name..":"..x)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    -- 改牌名会有隐患吗？
    local name = data.card.name == "analeptic" and "drugs" or "analeptic"
    local card = Fk:cloneCard(name, data.card.suit, data.card.number)
    for k, v in pairs(data.card) do
      if card[k] == nil then
        card[k] = v
      end
    end
    card.subcards = Card:getIdList(data.card)
    card.skillNames = data.card.skillNames
    card.skillName = self.name
    data.card = card
    player:drawCards(player:usedSkillTimes(self.name), self.name)
    if not player.dead then
      room:askForDiscard(player, 2, 2, true, self.name, false)
    end
  end,

  refresh_events = {fk.PreCardUse},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.card.name == "analeptic"
  end,
  on_refresh = function (self, event, target, player, data)
    data.extraUse = true
  end,
}
local zuiyin_targetmod = fk.CreateTargetModSkill{
  name = "#rfenghou__zuiyin_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and player:hasSkill(zuiyin) and card.name == "analeptic"
  end,
}
zuiyin:addRelatedSkill(zuiyin_targetmod)
ruanji:addSkill(zuiyin)

Fk:loadTranslationTable{
  ["rfenghou__zuiyin"] = "醉饮",
  [":rfenghou__zuiyin"] = "你使用【酒】无次数限制，且你使用【散】或【酒】时，可以改为使用另一张并摸X张牌，然后弃置两张牌。（X为此技能本回合发动次数）",
  ["#rfenghou__zuiyin-ask"] = "醉饮：你可以改为使用【%arg】，摸 %arg2 牌并弃 2 牌",
}

ruanji:addSkill("rfenghou__wenyan")



return extension
